package com.hss.mvp.base;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import com.hss.base.interfaces.IDestory;
import com.hss.mvp.utils.ActivityUtils;

/**
 * Created by Administrator on 2017/2/9.
 */

public abstract class BaseActivty extends AppCompatActivity implements IDestory{


     public void initIntentData(){

    }

    public void initData(){

    }

    public void initView(){

    }




   /* protected Toolbar initToolBar(String title) {

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        if (toolbar != null) {
            setSupportActionBar(toolbar);
//            TextView toolbaTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
//            toolbaTitle.setText(title);
        }
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }
        return toolbar;
    }

     Toolbar initToolBarAsHome(String title) {

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        if (toolbar != null) {
            setSupportActionBar(toolbar);
//            TextView toolbaTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
//            toolbaTitle.setText(title);
        }
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setDisplayShowTitleEnabled(false);
        }
        return toolbar;
    }*/


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case android.R.id.home:
                super.onBackPressed();//返回
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }

    }

    @Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }


    @Override
    public void destoryRes() {

    }


    @Override
    protected void onDestroy() {
        destoryRes();
        super.onDestroy();
    }

    /**
     * hss
     * 2017 2  11
     * @param cls fragment class
     * @param frameId   frameLayout id
     * @return  fragment
     */
    public  <T extends Fragment> T addFragment2Frame(Class<T> cls,int frameId) throws IllegalAccessException, InstantiationException {
        T fragment = null;
        fragment = (T) getSupportFragmentManager().findFragmentById(frameId);
        if (null == fragment){
                fragment = cls.newInstance();
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),
                        fragment, frameId);

        }
        return fragment;
    }
}
